<template>
<view class="content">
	<view :style='{"minHeight":"100vh","width":"100%","padding":"24rpx","position":"relative","background":"url(http://codegen.caihongy.cn/20240112/23f959aa396c4607b2f20ed40caa81e9.jpg) no-repeat center top / 100% auto,#f5f5f5","height":"auto"}'>
		<form :style='{"width":"100%","padding":"24rpx","borderRadius":"16rpx","background":"#fff","display":"block","height":"auto"}' class="app-update-pv">
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">景点编号</view>
				<view :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","flex":"1","background":"rgba(255,255,255,.6)","lineHeight":"80rpx","fontSize":"32rpx"}' class="right-input">
					{{ruleForm.jingdianbianhao}}
				</view>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">景点名称</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.jingdianmingcheng" v-model="ruleForm.jingdianmingcheng" placeholder="景点名称"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">景点类型</view>
				<picker :disabled="ro.jingdianleixing" :style='{"border":"2rpx solid #fff","width":"100%","padding":"0","flex":"1","background":"rgba(255,255,255,.6)","height":"auto"}' @change="jingdianleixingChange" :value="jingdianleixingIndex" :range="jingdianleixingOptions">
					<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"32rpx","color":"#666"}' class="uni-input">{{ruleForm.jingdianleixing?ruleForm.jingdianleixing:"请选择景点类型"}}</view>
				</picker>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">等级</view>
				<picker :disabled="ro.dengji" :style='{"border":"2rpx solid #fff","width":"100%","padding":"0","flex":"1","background":"rgba(255,255,255,.6)","height":"auto"}' @change="dengjiChange" :value="dengjiIndex" :range="dengjiOptions">
					<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"32rpx","color":"#666"}' class="uni-input">{{ruleForm.dengji?ruleForm.dengji:"请选择等级"}}</view>
				</picker>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="" @tap="jingdiantupianTap">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">景点图片</view>
				<image :style='{"width":"80rpx","margin":"0","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' class="avator" v-if="ruleForm.jingdiantupian" :src="baseUrl+ruleForm.jingdiantupian.split(',')[0]" mode="aspectFill"></image>
				<image :style='{"width":"80rpx","margin":"0","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' class="avator" v-else src="../../static/gen/upload.png" mode="aspectFill"></image>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">门票</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.menpiao" v-model.number="ruleForm.menpiao" placeholder="门票" type="number"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class=" input" @tap="yuyinjiangjieTap">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">语音讲解</view>
				<view class="right-input" :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","flex":"1","background":"rgba(255,255,255,.6)","lineHeight":"80rpx","fontSize":"32rpx"}'>
					{{ruleForm.yuyinjiangjie?ruleForm.yuyinjiangjie:'点击上传语音讲解'}}
				</view>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">人流量</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.renliuliang" v-model="ruleForm.renliuliang" placeholder="人流量"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">开放时段</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.kaifangshiduan" v-model="ruleForm.kaifangshiduan" placeholder="开放时段"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">服务电话</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.fuwudianhua" v-model="ruleForm.fuwudianhua" placeholder="服务电话"  type="text"></input>
			</view>
			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">详细地址</view>
				<input :style='{"border":"2rpx solid #fff","padding":"0","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"80rpx"}' :disabled="ro.xiangxidizhi" v-model="ruleForm.xiangxidizhi" placeholder="详细地址"  type="text"></input>
			</view>
 

			<view :style='{"padding":"0px 24rpx 12rpx","margin":"0 0 24rpx 0","borderColor":"#eee","alignItems":"center","flexWrap":"wrap","borderWidth":"0 0 2rpx","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"width":"100%","padding":"0 20rpx 0 0","lineHeight":"80rpx","fontSize":"32rpx","color":"#333","textAlign":"left"}' class="title">历史来源</view>
				<textarea :style='{"border":"2rpx solid #ddd","padding":"24rpx","margin":"0px","color":"#666","borderRadius":"8rpx","flex":"1","background":"rgba(255,255,255,.6)","fontSize":"32rpx","height":"360rpx"}' v-model="ruleForm.lishilaiyuan" placeholder="历史来源" :maxlength="-1"></textarea>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"#ccc","borderWidth":"0 0 0px 0","width":"100%","borderStyle":"solid","height":"auto"}' class="">
				<view :style='{"margin":"0 0 0 24rpx","color":"#999","width":"auto","lineHeight":"80rpx","fontSize":"32rpx","minWidth":"160rpx","fontWeight":"500"}' class="title">景点介绍</view>
                <xia-editor ref="editor" :style='{"border":"2rpx solid #ddd","minHeight":"360rpx","padding":"20rpx","color":"#666","borderRadius":"8rpx","background":"rgba(255,255,255,.6)","width":"100%","height":"auto"}' v-model="ruleForm.jingdianjieshao" placeholder="景点介绍" @editorChange="jingdianjieshaoChange"></xia-editor>
			</view>
			
			<view :style='{"width":"100%","flexWrap":"wrap","justifyContent":"space-between","display":"flex","height":"auto"}' class="btn" >
				<button :style='{"border":"0","padding":"0px","margin":"0 0 40rpx","color":"#fff","borderRadius":"32rpx","background":"#4AB030","width":"100%","lineHeight":"80rpx","fontSize":"32rpx","height":"80rpx"}' @tap="onSubmitTap" class="bg-red">提交</button>
			</view>
		</form>

		<w-picker  mode="dateTime" step="1" :current="false" :hasSecond="false" @confirm="clicktimeConfirm" ref="clicktime" themeColor="#333333"></w-picker>
	</view>
</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
    import xiaEditor from '@/components/xia-editor/xia-editor';
    import multipleSelect from "@/components/momo-multipleSelect/momo-multipleSelect";
	export default {
		data() {
			return {
				cross:'',
				ruleForm: {
				jingdianbianhao: this.getUUID(),
				jingdianmingcheng: '',
				jingdianleixing: '',
				dengji: '',
				jingdiantupian: '',
				menpiao: '',
				yuyinjiangjie: '',
				renliuliang: '',
				kaifangshiduan: '',
				fuwudianhua: '',
				xiangxidizhi: '',
				lishilaiyuan: '',
				jingdianjieshao: '',
				discussnum: '',
				storeupnum: '',
				},
				jingdianleixingOptions: [],
				jingdianleixingIndex: 0,
				dengjiOptions: [],
				dengjiIndex: 0,
				// 登录用户信息
				user: {},
                ro:{
                   jingdianbianhao : false,
                   jingdianmingcheng : false,
                   jingdianleixing : false,
                   dengji : false,
                   jingdiantupian : false,
                   menpiao : false,
                   yuyinjiangjie : false,
                   renliuliang : false,
                   kaifangshiduan : false,
                   fuwudianhua : false,
                   xiangxidizhi : false,
                   lishilaiyuan : false,
                   jingdianjieshao : false,
                   clicktime : false,
                   clicknum : false,
                   discussnum : false,
                   storeupnum : false,
                },
			}
		},
		components: {
			wPicker,
            xiaEditor,
            multipleSelect,
		},
		computed: {
			baseUrl() {
				return this.$base.url;
			},



		},
		async onLoad(options) {
			let table = uni.getStorageSync("nowTable");
			// 获取用户信息
			let res = await this.$api.session(table);
			this.user = res.data;
			
			// ss读取


			// 下拉框
			res = await this.$api.option(`jingdianleixing`,`jingdianleixing`,{});
			this.jingdianleixingOptions = res.data;
            this.jingdianleixingOptions.unshift("请选择景点类型");
			// 自定义下拉框值
			this.dengjiOptions = "AAAAA,AAAA,AAA,AA,A".split(',')

			// 如果有登录，获取登录后保存的userid
			this.ruleForm.userid = uni.getStorageSync("appUserid")
			if (options.refid) {
				// 如果上一级页面传递了refid，获取改refid数据信息
				this.ruleForm.refid = Number(options.refid);
				this.ruleForm.nickname = uni.getStorageSync("nickname");
			}
			// 如果是更新操作
			if (options.id) {
				this.ruleForm.id = options.id;
				// 获取信息
				res = await this.$api.info(`lvyoujingdian`, this.ruleForm.id);
				this.ruleForm = res.data;
			}
			// 跨表
			this.cross = options.cross;
			if(options.cross){
				var obj = uni.getStorageSync('crossObj');
				for (var o in obj){
					if(o=='jingdianbianhao'){
					this.ruleForm.jingdianbianhao = obj[o];
					this.ro.jingdianbianhao = true;
					continue;
					}
					if(o=='jingdianmingcheng'){
					this.ruleForm.jingdianmingcheng = obj[o];
					this.ro.jingdianmingcheng = true;
					continue;
					}
					if(o=='jingdianleixing'){
					this.ruleForm.jingdianleixing = obj[o];
					this.ro.jingdianleixing = true;
					continue;
					}
					if(o=='dengji'){
					this.ruleForm.dengji = obj[o];
					this.ro.dengji = true;
					continue;
					}
					if(o=='jingdiantupian'){
					this.ruleForm.jingdiantupian = obj[o].split(",")[0];
					this.ro.jingdiantupian = true;
					continue;
					}
					if(o=='menpiao'){
					this.ruleForm.menpiao = obj[o];
					this.ro.menpiao = true;
					continue;
					}
					if(o=='yuyinjiangjie'){
					this.ruleForm.yuyinjiangjie = obj[o];
					this.ro.yuyinjiangjie = true;
					continue;
					}
					if(o=='renliuliang'){
					this.ruleForm.renliuliang = obj[o];
					this.ro.renliuliang = true;
					continue;
					}
					if(o=='kaifangshiduan'){
					this.ruleForm.kaifangshiduan = obj[o];
					this.ro.kaifangshiduan = true;
					continue;
					}
					if(o=='fuwudianhua'){
					this.ruleForm.fuwudianhua = obj[o];
					this.ro.fuwudianhua = true;
					continue;
					}
					if(o=='xiangxidizhi'){
					this.ruleForm.xiangxidizhi = obj[o];
					this.ro.xiangxidizhi = true;
					continue;
					}
					if(o=='lishilaiyuan'){
					this.ruleForm.lishilaiyuan = obj[o];
					this.ro.lishilaiyuan = true;
					continue;
					}
					if(o=='jingdianjieshao'){
					this.ruleForm.jingdianjieshao = obj[o];
					this.ro.jingdianjieshao = true;
					continue;
					}
					if(o=='clicktime'){
					this.ruleForm.clicktime = obj[o];
					this.ro.clicktime = true;
					continue;
					}
					if(o=='clicknum'){
					this.ruleForm.clicknum = obj[o];
					this.ro.clicknum = true;
					continue;
					}
					if(o=='discussnum'){
					this.ruleForm.discussnum = obj[o];
					this.ro.discussnum = true;
					continue;
					}
					if(o=='storeupnum'){
					this.ruleForm.storeupnum = obj[o];
					this.ro.storeupnum = true;
					continue;
					}
				}
			}
			this.styleChange()
            this.$forceUpdate()
			
			if (uni.getStorageSync('raffleType') && uni.getStorageSync('raffleType') != null) {
				uni.removeStorageSync('raffleType')
				setTimeout(() => {
					this.onSubmitTap()
				}, 300)
			}
		},
		methods: {
            jingdianjieshaoChange(e) {
                this.ruleForm.jingdianjieshao = e
            },
			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('.app-update-pv . .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.addUpdateForm.input.content.backgroundColor
					// })
				})
			},

			// 多级联动参数


			// 日长控件选择日期时间
			clicktimeConfirm(val) {
				console.log(val)
				this.ruleForm.clicktime = val.result;
				this.$forceUpdate();
			},

			// 下拉变化
			jingdianleixingChange(e) {
				this.jingdianleixingIndex = e.target.value
				this.ruleForm.jingdianleixing = this.jingdianleixingOptions[this.jingdianleixingIndex]
			},
			// 下拉变化
			dengjiChange(e) {
				this.dengjiIndex = e.target.value
				this.ruleForm.dengji = this.dengjiOptions[this.dengjiIndex]
			},

			jingdiantupianTap() {
				let _this = this;
				this.$api.upload(function(res) {
					_this.ruleForm.jingdiantupian = 'upload/' + res.file;
					_this.$forceUpdate();
					_this.$nextTick(()=>{
						_this.styleChange()
					})
				});
			},
			yuyinjiangjieTap () {
				let _this = this;
				this.$api.uploadMedia(function(res) {
					_this.ruleForm.yuyinjiangjie = 'upload/' + res.file;
					_this.$forceUpdate();
				});
			},

			getUUID () {
				return new Date().getTime();
			},
			async onSubmitTap() {
				if(this.ruleForm.jingdianbianhao){
					this.ruleForm.jingdianbianhao = String(this.ruleForm.jingdianbianhao)
				}
//跨表计算判断
				var obj;
				if((!this.ruleForm.jingdianmingcheng)){
					this.$utils.msg(`景点名称不能为空`);
					return
				}
				if((!this.ruleForm.menpiao)){
					this.$utils.msg(`门票不能为空`);
					return
				}
				if(this.ruleForm.menpiao&&(!this.$validate.isIntNumer(this.ruleForm.menpiao))){
					this.$utils.msg(`门票应输入整数`);
					return
				}
				if(this.ruleForm.fuwudianhua&&(!this.$validate.isMobile(this.ruleForm.fuwudianhua))){
					this.$utils.msg(`服务电话应输入手机格式`);
					return
				}
				if(this.ruleForm.clicknum&&(!this.$validate.isIntNumer(this.ruleForm.clicknum))){
					this.$utils.msg(`点击次数应输入整数`);
					return
				}
				if(this.ruleForm.discussnum&&(!this.$validate.isIntNumer(this.ruleForm.discussnum))){
					this.$utils.msg(`评论数应输入整数`);
					return
				}
				if(this.ruleForm.storeupnum&&(!this.$validate.isIntNumer(this.ruleForm.storeupnum))){
					this.$utils.msg(`收藏数应输入整数`);
					return
				}
				//更新跨表属性
				var crossuserid;
				var crossrefid;
				var crossoptnum;
				if(this.cross){
                    uni.setStorageSync('crossCleanType',true);
					var statusColumnName = uni.getStorageSync('statusColumnName');
					var statusColumnValue = uni.getStorageSync('statusColumnValue');
					if(statusColumnName!='') {
                        if(!obj) {
						    obj = uni.getStorageSync('crossObj');
                        }
						if(!statusColumnName.startsWith("[")) {
							for (var o in obj){
								if(o==statusColumnName){
									obj[o] = statusColumnValue;
								}

							}
							var table = uni.getStorageSync('crossTable');
							await this.$api.update(`${table}`, obj);
						} else {
						       crossuserid=Number(uni.getStorageSync('appUserid'));
						       crossrefid=obj['id'];
						       crossoptnum=uni.getStorageSync('statusColumnName');
						       crossoptnum=crossoptnum.replace(/\[/,"").replace(/\]/,"");
						}
					}
				}
				if(crossrefid && crossuserid) {
					this.ruleForm.crossuserid=crossuserid;
					this.ruleForm.crossrefid=crossrefid;
					let params = {
						page: 1,
						limit:10,
						crossuserid:crossuserid,
						crossrefid:crossrefid,
					}
					let res = await this.$api.list(`lvyoujingdian`, params);
					if (res.data.total >= crossoptnum) {
						this.$utils.msg(uni.getStorageSync('tips'));
                        uni.removeStorageSync('crossCleanType');
						return false;
					} else {
                //跨表计算
						if(this.ruleForm.id){
							await this.$api.update(`lvyoujingdian`, this.ruleForm);
						}else{
							await this.$api.add(`lvyoujingdian`, this.ruleForm);
						}
						this.$utils.msgBack('提交成功');
					}
				} else {
                //跨表计算
					if(this.ruleForm.id){
						await this.$api.update(`lvyoujingdian`, this.ruleForm);
					}else{
						await this.$api.add(`lvyoujingdian`, this.ruleForm);
					}
					this.$utils.msgBack('提交成功');
				}
			},
			optionsChange(e) {
				this.index = e.target.value
			},
			bindDateChange(e) {
				this.date = e.target.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			toggleTab(str) {
				if(this.ro[str]){
					return false
				}
				this.$refs[str].show();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
